package cn.it.shop.action;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import cn.it.shop.pojo.Forder;
import cn.it.shop.pojo.Goods;
import cn.it.shop.pojo.Sorder;

@Controller
@Scope("prototype")
public class SorderAction extends BaseAction<Sorder> {

	public String buy$(){
		// 1: 通过商品ID查询商品信息 goodsService
		Goods goods=goodsService.get(model.getId());		
		// 2: 把goods 转化sorder
		model.setId(null);
		model.setName(goods.getName());
		model.setNumber(1);
		model.setPrice(goods.getPrice());
		model.setGoods(goods);
		// 2: 从session中获取购物车
		Forder forder=(Forder)session.get("forder");
		// 3:把goods存放到sorder中,要判断是否重复
		forder=sorderService.addSorder(forder,model);
		// 4:更新总价格
		forder.setTotal(forderService.cluTotal(forder));
		// 5: 把购物车存放到session中
		session.put("forder", forder);
		return "showCar";
	}
}
